﻿using Pay.Core;
using Pay.DTO;
using Pay.TO;
using Pay.IService;
using System.Collections.Generic;
using System.Web.Mvc;

namespace Pay.Web.Areas.Admin.Controllers {
	public class GradeController : AdminController {
		private IGradeService _iGradeService;
        private IMerchantService _iMerchantService;

        public GradeController(IGradeService iGradeService, IMerchantService iMerchantService) {
			_iGradeService = iGradeService;
			_iMerchantService = iMerchantService;
		}

		#region 商户级别
		[HttpGet]
		public JsonResult Get(long id) {
			var result = _iGradeService.Get(id);
			return Json(ResultToJson.Json(result), JsonRequestBehavior.AllowGet);
		}
		[HttpGet]
		public JsonResult Gets(string id) {
			var Manages = _iGradeService.Gets(id);
			return Json(ResultToJson.Json(Manages), JsonRequestBehavior.AllowGet);
		}
		//[HttpPut]
		//[ValidateInput(false)]
		//public JsonResult Put(long id) {
		//	var dto = _iGradeService.Get(id);
		//	TryUpdateModel(dto);
		//	var result = _iGradeService.Update(dto);
		//	return Json(ResultToJson.Json(result > 0 ? "保存成功" : "没有修改任何内容", result), JsonRequestBehavior.AllowGet);
		//}
		[HttpPost]
		[ValidateInput(false)]
		public JsonResult Post(grade_dto dto) {
            var merchant = _iMerchantService.Get(currentUser.user_id);
            if (merchant != null)
                dto.merchant_no = merchant.merchant_no;
			var result = _iGradeService.Add(dto);
			return Json(ResultToJson.Json(result > 0 ? "保存成功" : "保存失败", result), JsonRequestBehavior.AllowGet);
		}
		[HttpDelete]
		public JsonResult Delete(long id) {
			var result = _iGradeService.Delete(id);
			return Json(ResultToJson.Json(result > 0 ? "删除成功" : "删除失败", result), JsonRequestBehavior.AllowGet);
		}
		#endregion
	}
}